package com.ojoin.ojoin.eb_spider.service.stat;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.ojoin.ojoin.eb_spider.utils.WebServiceUtils;
import com.ojoin.trade.common.utils.CommonUtils;
import com.ojoin.trade.common.utils.LogUtils;
import com.ojoin.trade.common.utils.TimeUtils;
import com.ojoin.trade.supplyloan_core.web.domain.TbCatchdataStrategy;
import com.ojoin.trade.supplyloan_core.web.domain.TbSlLoanStatTotal;
import com.ojoin.trade.supplyloan_core.web.domain.TbSlPlatformUser;
import com.ojoin.trade.supplyloan_core.web.domain.TbSlSupplyInventory;
import com.ojoin.trade.supplyloan_core.web.domain.TbSlSupplyPayment;
@Service
public class SupplierTMALLstat  extends BaseStatTotal{

	private Logger log = LoggerFactory.getLogger(SupplierTMALLstat.class);
	
	@Override
	public void invoke(TbSlPlatformUser user,TbCatchdataStrategy ca, TbSlLoanStatTotal total) throws Exception {
		
		String stime = WebServiceUtils.getPaymentLastsettlementDate(user.getId())
				.replace("/", "-");

		if (CommonUtils.isEmpty(stime)) {
			stime = WebServiceUtils.getPaymentLastInsertTime( user.getId());
		}
		String etime = TimeUtils.getCurDate(); 

		long inveInMoney = WebServiceUtils.getSupplyInventoryMoneyByplateformId(user.getId(),ca, stime, etime, TbSlSupplyInventory.IN);
		
		long inveOutMoney = WebServiceUtils.getSupplyInventoryMoneyByplateformId(user.getId(),ca, stime, etime, TbSlSupplyInventory.OUT);

		long waitpay = WebServiceUtils.getSupplyPaymentMoneyByplateformId(user.getId(),ca, null, null, TbSlSupplyPayment.WAITPAY);
		
		long settorcheck = WebServiceUtils.getSupplyPaymentMoneyByplateformId(user.getId(),ca, null, null, TbSlSupplyPayment.CHECKEDPAY);
		
		
		total.setTotalUnsettleInstoreorder(inveInMoney);
		total.setTotalUnenterinRefundorder(inveOutMoney);
		total.setTotalUnpaySettleorder(waitpay);
		total.setTotalUnpaySettleorderCheck(settorcheck);

		LogUtils.info(
				log,
				"  %s --> [ store in time:%s ] + [store out time:%s] + [Unpay time:%s] +[checkedpay time:%s ]",
				user.getUsername(), etime, etime, etime, etime);
		
		
		
		
		
		
		
	
	}

}
